#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QMenu>
#include <QAction>
#include <QMouseEvent>
#include <QList>
#include <qlabel.h>
#include <QNetworkAccessManager>
#include <QMessageBox>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QByteArray>
#include <QPainter>
#include <QTimer>
#include <qlist.h>

#include "WeatherTool.h"
#include "weatherdate.h"

QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr); 
    ~Widget();

    virtual bool eventFilter(QObject *watched, QEvent *event);
protected:
    //bool eventFilter(QObject* watched,QEvent* event);
    void mouseMoveEvent(QMouseEvent *event);
    void mousePressEvent(QMouseEvent* event);
    void contextMenuEvent(QContextMenuEvent* event);//鼠标右击退出函数
    void getWeatherInfo(QNetworkAccessManager* manager);
    void parseJson(QByteArray& bytes);
    void setLabelContent();
    void paintSunRiseSet();//日出日落的绘制
    void paintCurve();//绘制温度曲线
private slots:
    void slot_exitApp();//槽函数
    void replayFinished(QNetworkReply* reply);

    void on_searchBT_clicked();

    void on_refreshBT_clicked();

private:
    Ui::Widget *ui;
    QMenu* exitMenu;//右键退出的菜单
    QAction* exitAct;//退出的行为，要绑定菜单
    QPoint mPos;//窗口移动需要用的点
    //UI
    QList<QLabel *> forecast_week_list; //星期
    QList<QLabel *> forecast_date_list; //日期
    QList<QLabel *> forecast_aqi_list; //天气指数
    QList<QLabel *> forecast_type_list; //天气
    QList<QLabel *> forecast_typeIco_list; //天气图标
    QList<QLabel *> forecast_high_list; //高温
    QList<QLabel *> forecast_low_list; //低温

    //网络请求
    QString url;         //接口链接
    QString city;          //访问的城市
    QString cityTmp;        //临时存放城市变量，防止输入错误城市的时候，原来的城市名称还在
    WeatherTool tool;       //天气工具对象
    QNetworkAccessManager* manager;

    //本地数据
    Today today;
    Forecast forecast[6];

    static const QPoint sun[2];//日出日落的底线
    static const QRect sunRiseSet[2];//日出日落时间
    static const QRect rect[2];//日出日落圆弧

    QTimer* sunTimer;//定时器
};
#endif // WIDGET_H
